package com.lc.railway.ui.activity;

import android.os.Bundle;
import android.widget.EditText;

import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.railway.R;
import com.lc.railway.app.AppActivity;
import com.lc.railway.http.request.RegisterApi;
import com.lc.railway.http.response.RegisterBean;
import com.lc.railway.util.CourseUtils;
import com.lc.widget.view.PasswordEditText;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author : Android 轮子哥
 * github : https://github.com/getActivity/AndroidProject
 * time   : 2018/10/18
 * desc   : 注册界面
 */
public final class RegisterActivity extends AppActivity {


    @BindView(R.id.et_register_name)
    EditText etRegisterName;
    @BindView(R.id.et_register_work)
    EditText etRegisterWork;
    @BindView(R.id.et_register_job)
    EditText etRegisterJob;
    @BindView(R.id.et_register_alarm)
    EditText etRegisterAlarm;
    @BindView(R.id.et_register_password)
    PasswordEditText etRegisterPassword;

    @Override
    protected int getLayoutId() {
        return R.layout.register_activity;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.btn_register)
    public void onClick() {
        if (CourseUtils.isNullOrEmpty(etRegisterName.getText().toString().trim())){
            toast("请输入您的姓名");
            return;
        }
        if (CourseUtils.isNullOrEmpty(etRegisterWork.getText().toString().trim())){
            toast("请输入您的单位");
            return;
        }
        if (CourseUtils.isNullOrEmpty(etRegisterJob.getText().toString().trim())){
            toast("请输入您的职务");
            return;
        }
        if (CourseUtils.isNullOrEmpty(etRegisterAlarm.getText().toString().trim())){
            toast("请输入您的警号");
            return;
        }
        if (CourseUtils.isNullOrEmpty(etRegisterPassword.getText().toString().trim())){
            toast("请设置您的密码");
            return;
        }
//        api_login/add
        register();
    }

    private void register() {
        EasyHttp.post(this)
                .api(new RegisterApi().setCnname(etRegisterName.getText().toString().trim()).setUnit(etRegisterWork.getText().toString().trim()).setJob(etRegisterJob.getText().toString().trim()).setUsername(etRegisterAlarm.getText().toString().trim()).setPassword(etRegisterPassword.getText().toString()).setPassworded(etRegisterPassword.getText().toString()))
                .request(new HttpCallback<RegisterBean>(this) {
                    @Override
                    public void onSucceed(RegisterBean data) {
                        toast(data.getError_msg());
                      if (data.getError_code()==200){
                          finish();
                      }
                    }
                    });


                }


}